home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / GMS / Source / C / Screens / Mirror.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-01  |  2.3 KB  |  84 lines

  1. /*
  2. ** Mirror Demo
  3. ** -----------
  4. ** Demo of the mirroring effect.  When this effect is combined with a
  5. ** decrease in palette values at the same line, you can create the illusion of
  6. ** water.
  7. ** 
  8. ** Use the mouse to move the mirror around. LMB exits.
  9. **
  10. ** To compile with SAS/C:
  11. **
  12. **    1> sc Mirror.c link startup=LIB:gms.o data=far
  13. **
  14. */
  15.  
  16. #include <proto/games.h>
  17.  
  18. extern struct GMSBase *GMSBase;
  19. ULONG _XCEXIT = NULL;
  20. ULONG PREFSNAME = DEFAULT;
  21.  
  22. ULONG WaterPalette[] = {
  23.   0x000000,0x001000,0x706050,0x705040,0x604040,0x403020,0x302020,0x100000,
  24.   0x200000,0x202020,0x707000,0x201010,0x606000,0x002000,0x200000,0x404000,
  25.   0x103000,0x103000,0x104010,0x204010,0x205010,0x205020,0x303030,0x306020,
  26.   0x304040,0x405050,0x606060,0x400000,0x400000,0x500010,0x300000,0x300000
  27. };
  28.  
  29. ULONG Rasterlist[] = {
  30.   WAITLINE(190),
  31.   MIRROR,
  32.   NEWPALETTE(0,32,WaterPalette),
  33.   RASTEND
  34. };
  35.  
  36. void main(void)
  37. {
  38.   struct GameScreen *GameScreen;
  39.   struct Picture *MirrorPic;
  40.   ULONG  mouse;
  41.   WORD   maxX,maxY;
  42.  
  43.   if (MirrorPic = LoadPicFile("GMS:demos/data/PIC.Green",VIDEOMEM|GETPALETTE)) {
  44.  
  45.      if (GameScreen = AddScreenTags(TAGS_GAMESCREEN,NULL,
  46.         GSA_MemPtr1,MirrorPic->Data,
  47.         GSA_Palette,MirrorPic->Palette,
  48.         GSA_Rasterlist,Rasterlist,
  49.         GSA_ScrWidth,320,
  50.         GSA_ScrHeight,256,
  51.         GSA_PicWidth,MirrorPic->Width,
  52.         GSA_PicHeight,MirrorPic->Height,
  53.         GSA_Planes,MirrorPic->Planes,
  54.         GSA_AmtColours,MirrorPic->AmtColours,
  55.         GSA_Attrib,HSCROLL|VSCROLL,
  56.         GSA_ScrMode,MirrorPic->ScrMode,
  57.         GSA_ScrType,MirrorPic->ScrType,
  58.         TAGEND)) {
  59.  
  60.        ShowScreen(GameScreen);
  61.        InitJoyPorts();
  62.  
  63.        maxX = (GameScreen->PicWidth)-(GameScreen->ScrWidth);
  64.        maxY = (GameScreen->PicHeight)-(GameScreen->ScrHeight);
  65.  
  66.        do {
  67.           mouse = ReadJoyPort(JPORT1,JT_ZBXY);
  68.           GameScreen->PicXOffset += (BYTE)(mouse >> 8);
  69.           GameScreen->PicYOffset += (BYTE)(mouse);
  70.           if (GameScreen->PicXOffset < 0) GameScreen->PicXOffset = 0;
  71.           if (GameScreen->PicXOffset > maxX) GameScreen->PicXOffset = maxX;
  72.           if (GameScreen->PicYOffset < 0) GameScreen->PicYOffset = 0;
  73.           if (GameScreen->PicYOffset > maxY) GameScreen->PicYOffset = maxY;
  74.           MovePicture(GameScreen);
  75.           WaitVBL();
  76.        } while (!(mouse & MB_LMB));
  77.  
  78.      DeleteScreen(GameScreen);
  79.      }
  80.   FreePic(MirrorPic);
  81.   }
  82. }
  83.  
  84.